using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Resources;

using WP.Commons;
using WP.Controls;
using WP.Controls.GridColumn;
using WP.DB;
using WP.Modules;

namespace WP.MF.Form
{
    public partial class frmMUnLockMtn : BaseQryRpt      
    {
        private ArrayList strRecID=new ArrayList();
        private DBAccess dbAccess = new DBAccess(false, false);
        public frmMUnLockMtn()
        {
            InitializeComponent();
            LoadAllControl(new ArrayList(this.Controls));
            this.MinimumSize = this.Size;
        }
        private void frmMUnLockMtn_Load(object sender, EventArgs e)
        {
            InitData();
        }
        private void CmdSel_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < ListLock.Items.Count; i++)
            {
                ListLock.Items[i].Checked = true;
            }
        }
        private void CmdUnSel_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < ListLock.Items.Count; i++)
            {
                ListLock.Items[i].Checked = false;
            }
        }
        private void cmdOK_Click(object sender, EventArgs e)
        {
            string strSql = string.Empty;
            for (int i = 0; i < ListLock.Items.Count; i++)
            {
                if (ListLock.Items[i].Checked)
                {
                    if (this.CurrentMenuInfo.iParameter == 0)
                    {
                        strSql = "delete from msyslock where recid=" + strRecID[i].ToString();
                        dbAccess.ExecuteSql(strSql);
                    }
                    else
                    {
                        strSql = "delete from msyslock2 where recid=" + strRecID[i].ToString();
                        dbAccess.ExecuteSql(strSql);
                    }
                }
            }
            this.Close();
        }
        private void cmdCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void InitData()
        {
            string strSql = string.Empty;
            DataTable DtItem = new DataTable();
            string strItem = string.Empty;

            if (this.CurrentMenuInfo.iParameter == 0)
            {
                strSql = "select a.recid,a.TableName,a.DocNo,a.LockRecId,a.UserName,a.ComputerName from mSysLock a  order by  a.TableName,a.LockRecId,a.UserName,a.ComputerName,a.SessionID";
                DtItem = dbAccess.GetDataTable(strSql);
                ListViewItem ListView;
                ListViewItem[] Lv = new ListViewItem[DtItem.Rows.Count];
                for (int i = 0; i < DtItem.Rows.Count; i++)
                {
                    ListView = new ListViewItem("".ToString(), i);
                    Lv[i] = ListView;
                    for (int j = 1; j < DtItem.Columns.Count; j++)
                    {
                        ListView.SubItems.Add(DtItem.Rows[i][j].ToString().Trim());
                    }
                    strRecID.Add(DtItem.Rows[i]["recid"]);
                }
                this.ListLock.Columns.Add("", 20, HorizontalAlignment.Center);
                for (int i = 1; i < DtItem.Columns.Count; i++)
                {
                    this.ListLock.Columns.Add(DtItem.Columns[i].Caption, 100, HorizontalAlignment.Left);
                }
                ListLock.Items.AddRange(Lv);
            }
            else
            {
                strSql = "select a.recid,a.LockExpress,a.ProgName,a.UserName,a.ComputerName from mSysLock2 a  order by  a.ProgName,a.recid,a.UserName,a.ComputerName,a.SessionID";
                DtItem = dbAccess.GetDataTable(strSql);
                ListViewItem ListView;
                ListViewItem[] Lv = new ListViewItem[DtItem.Rows.Count];
                for (int i = 0; i < DtItem.Rows.Count; i++)
                {
                    ListView = new ListViewItem("".ToString(), i);
                    Lv[i] = ListView;
                    for (int j = 1; j < DtItem.Columns.Count; j++)
                    {
                        ListView.SubItems.Add(DtItem.Rows[i][j].ToString().Trim());
                    }
                    strRecID.Add(DtItem.Rows[i]["recid"]);
                }
                this.ListLock.Columns.Add("", 20, HorizontalAlignment.Center);
                for (int i = 1; i < DtItem.Columns.Count; i++)
                {
                    this.ListLock.Columns.Add(DtItem.Columns[i].Caption, (DtItem.Columns[i].Caption == "LockExpress" ? 250 : 100), HorizontalAlignment.Left);
                }
                ListLock.Items.AddRange(Lv);
            }
        }

        private void btnHelp_Click(object sender, EventArgs e)
        {
            base.OnHelp();
        }
    }
}